package text;

import java.util.Arrays;
import java.util.Random;

public class ShellSort {
    public static void main(String[] args) {
        sort();
    }
    public static void sort() {
        Random a = new Random();
        int[] x = new int[10];
        for (int i = 0; i < x.length; i++) {
            x[i] = a.nextInt(1000);
        }
        System.out.println("数组的初始样子" + Arrays.toString(x));
        System.out.println("开始排序");
        for (int gap = x.length/2;gap>0;gap /= 2){
            for (int i = gap;i<x.length;i++){
                /*当前需要确定位置的元素的下标*/
               for (int j = i-gap;j>=0;j -= gap){
                   if (x[j]>x[j+gap]){
                       int tamp = x[j];
                       x[j] = x[j+gap];
                       x[j+gap] = tamp;
                   }else {
                       break;
                   }
                }
                System.out.println(Arrays.toString(x));
            }
        }
    }
}